//
//  ViewController.m
//  04-UIControl
//
//  Created by 402030900@qq.com on 16/7/19.
//  Copyright © 2016年 402030900@qq.com. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 一. UISwitch
    // switch 宽高不影响控件大小,只有x,y
    UISwitch * switch1 = [[UISwitch alloc]initWithFrame:CGRectMake(100, 100, 0, 0)];
    [self.view addSubview:switch1];
    // 1.设置开关控件内部的颜色
    switch1.onTintColor = [UIColor yellowColor];
    // 2.边框 切换时到关闭时的颜色 (null_resettable)
    switch1.tintColor = [UIColor cyanColor];
    // 3.开关按钮(圆圈)的颜色
    switch1.thumbTintColor = [UIColor blackColor];
    // 4.打开时的图片,iOS7后失效
    switch1.onImage = [UIImage imageNamed:@"01.jpg"];
    // 5.关闭时的图片,iOS7后失效
    switch1.offImage = [UIImage imageNamed:@"01.jpg"];
    // 6. 判断开闭状态
    // 可以通过setter方法,改变switch1 初始状态
    NSLog(@"%@",switch1.isOn ? @"YES" : @"NO");
    switch1.on = YES;
    [switch1 setOn:YES animated:YES];
    // 7.添加绑定事件(与Button相同)
    [switch1 addTarget:self action:@selector(switchAction:) forControlEvents:(UIControlEventValueChanged)];
    // 二.UISlider
    // 不影响控件的高度,控件用于居中于视图中间
    UISlider * slider = [[UISlider alloc] initWithFrame:CGRectMake(20, 200, 200, 40)];
    [self.view addSubview:slider];
    // 滑块最小值.可变
    slider.minimumValue = 0.0;
    // 滑块最大值.可变
    slider.maximumValue = 100.0;
    // 当前滑块的值(.f)
    slider.value = 50.0;
    //    // 滑块以左的颜色
    //    slider.minimumTrackTintColor = [UIColor redColor];
    //    // 滑块以右的颜色
    //    slider.maximumTrackTintColor = [UIColor greenColor];
    //    // 滑块的颜色
    //    slider.thumbTintColor = [UIColor blackColor];
    slider.backgroundColor = [UIColor blackColor];
    [slider setValue:20 animated:YES];
    // NO: 手松开才触发方法
    slider.continuous = NO;
    [slider addTarget:self action:@selector(sliderAction:) forControlEvents:(UIControlEventValueChanged)];
    //     // 显示原点的图片
    //    [slider setThumbImage:[UIImage imageNamed:@"01"] forState:(UIControlStateNormal)];
    //     // 最小值显示的图片
    //        slider.minimumValueImage = [UIImage imageNamed:@"01"];
    //     // 最大值显示的图片
    //    slider.maximumValueImage = [UIImage imageNamed:@"01"];
    // 设置 进度条滑块右侧图片
    [slider setMaximumTrackImage:[UIImage imageNamed: @"player_slider_playback_right"] forState:(UIControlStateNormal)];
    // 设置 进度条滑块左侧图片
    [slider setMinimumTrackImage:[UIImage imageNamed:@"player_slider_playback_left"] forState:(UIControlStateNormal)];
    // 设置 进度条滑块图片
    [slider setThumbImage:[UIImage imageNamed:@"player_slider_playback_thumb"] forState:(UIControlStateNormal)];
    
    // 三. UISegmentedControl
    UISegmentedControl * segment = [[UISegmentedControl alloc]initWithItems:@[@"first",@"second",@"third",@"fourth",@"fifth",@"sixth"]];
    [self.view addSubview:segment];
    segment.tag = 1000;
    // segment 不给frame 系统会自动计算大小
    segment.frame = CGRectMake(20, 20, 335, 50);
    // 1.momentry // 设置为YES,如果点击选中没有选中效果,默认为NO
    segment.momentary = YES;
    // 2.numberOfSegments 分段控制器的Item的个数
    NSUInteger numberOfSegments = segment.numberOfSegments;
    NSLog(@"分段控制器的Item的个数:%lu",numberOfSegments);
    UIButton * insertItem = [UIButton buttonWithType:(UIButtonTypeSystem)];
    insertItem.frame = CGRectMake(10, 300, 100, 50);
    insertItem.backgroundColor = [UIColor redColor];
    [self.view addSubview:insertItem];
    [insertItem addTarget:self action:@selector(addSegmentItem:) forControlEvents:(UIControlEventTouchUpInside)];
    // 3. insertSegmentWithTitle:  atIndex:  animated:
    // 4. remove
    // 5. setTitle:forSegmentAtIndex: 修改对应下标的标题
    [segment setTitle:@"被修改" forSegmentAtIndex:1];
    // 6. setWidth:  forSegmentAtIndex: 默认是0.0
    [segment setWidth:0 forSegmentAtIndex:0];
    // 7. 设置对下标内容的偏移
    [segment setContentOffset:CGSizeMake(0, 20) forSegmentAtIndex:0];
    // 8. 是否可以被选中
    [segment setEnabled:NO forSegmentAtIndex:0];
    // 9. 选中的下标
    segment.selectedSegmentIndex = 1;
    // 10. 文字及边框颜色
    segment.tintColor = [UIColor blackColor];
    // 11. apportionsSegmentWidthsByContent 默认为NO
    // 如果分段控制器的段宽为0时,并且该属性为yes,系统会自动计算
    segment.apportionsSegmentWidthsByContent = YES;
    // 12.segment 绑定事件
    [segment addTarget:self action:@selector(segmentControl:) forControlEvents:(UIControlEventValueChanged)];
    // 四.pageControl
    UIPageControl * pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(20, 400, 200, 50)];
    pageControl.backgroundColor = [UIColor blackColor];
    [self.view addSubview:pageControl];
    // 1.分页控制器的页数 默认为 0
    pageControl.numberOfPages = 5;
    // 2.当前页
    pageControl.currentPage = 0;
    // 3.当只有一页时隐藏
    pageControl.hidesForSinglePage = YES;
    // 4.获取到点的大小
    CGSize size = [pageControl sizeForNumberOfPages:0];
    NSLog(@"%@",NSStringFromCGSize(size));
    // 5.未选中的默认颜色
    pageControl.pageIndicatorTintColor = [UIColor greenColor];
    // 6.当前页的颜色
    pageControl.currentPageIndicatorTintColor = [UIColor redColor];
    // 7.绑定事件
    [pageControl addTarget:self action:@selector(pageControlChange:) forControlEvents:(UIControlEventValueChanged)];
    // 8.关闭系统事件page的切换,直到调用updateCurrentPageDisplay方法才会显示
    pageControl.defersCurrentPageDisplay = YES;
    
    
    // Do any additional setup after loading the view, typically from a nib.
}
// switch触发的事件
-(void)switchAction:(UISwitch *)switch1{
    // 根据switch的状态,决定触发什么样的事件
    if (switch1.on == YES) {
        NSLog(@"开");
    }else{
        NSLog(@"关");
    }
}
// Slider触发事件
-(void)sliderAction:(UISlider *)slider{
    NSLog(@"%f",slider.value);
}
// segment
-(void)addSegmentItem:(UIButton *)button{
    UISegmentedControl * segment = [self.view viewWithTag:1000];
    [segment insertSegmentWithTitle:@"seventh" atIndex:6 animated:YES];
}
-(void)segmentControl:(UISegmentedControl *)segmentControl{
    switch (segmentControl.selectedSegmentIndex) {
        case 1:
            break;
        case 2:
            break;
        default:
            break;
    }
    NSLog(@"%ld",segmentControl.selectedSegmentIndex);
}
// pageControl
-(void)pageControlChange:(UIPageControl *)pageControl{
    NSLog(@"change");
    [pageControl updateCurrentPageDisplay];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
